﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Manage_AddClass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Write("<script>alert('请先登录!');window.location.href='../Login.aspx'</script>");


        }
        else
        {
            if (!IsPostBack)
            {
                int id = 10;
                string sql = "select * from Employee where dutyid="+id+"";
                SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(sql,con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                DropDownList1.DataSource = ds;
                DropDownList1.DataTextField = "name";
                DropDownList1.DataBind();
                
                con.Close();
            }
        }
      
    }

  
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        string UserName=Session["UserName"].ToString();
        string ClassID=this.TextBox1.Text.Trim();
        string EntranceTime = this.TextBox3.Text;
        string TeacherName = DropDownList1.SelectedItem.Text;
        string Grade=this.TextBox5.Text.Trim();
        string State=this.TextBox6.Text.Trim();
        
        try
        {
            int ManCount = Convert.ToInt32(TextBox2.Text.Trim());
            if (ClassID == "" || TeacherName == "")
            {
                Response.Write("<script>alert('请填写完整资料')</script>");
            }
            else
            {
                string WorkInfo = "添加" + ClassID + "班";
                SqlInsert ql = new SqlInsert();
                ql.InsertClassInfo(ClassID, EntranceTime, ManCount, TeacherName, Grade, State);
                ql.InsertWorkLog(UserName, DateTime.Now.ToString(), WorkInfo);
                Response.Write("<script>alert('添加成功！！');window.location.href='ClassInfo.aspx';</script>");
                



            }
        
        }
        catch
        {
            Response.Write("<script>alert('请填写完整资料')</script>");
        }
    }
}
